﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ordina.SharePoint.RemoveShareFollow.Controls
{
    public class ShowHideSF : WebControl
    {
        private const string logClass = "ShowHideSF";
        private const string key = "ShowHideSF";

        public bool Debug { get; set; }

        protected override void Render(HtmlTextWriter writer)
        {
            if (Debug)
            {
                writer.WriteLine("<!-- ShowHideSF Script -->");
                writer.WriteLine("<!-- Key: " + key + " -->");
            }

            SPWeb currentWeb = SPContext.Current.Web;
            bool showSF = false;
            
            bool containsKey = currentWeb.Properties.ContainsKey(key);
            
            if (containsKey)
            {
                string value = currentWeb.Properties[key];

                if (Debug)
                {
                    writer.WriteLine("<!-- Value: " + value + " -->");
                }

                if (value.ToLower() == "true")
                {
                    showSF = true;
                }
            }

            if (showSF)
            {
                writer.WriteLine("<!-- ShowHideSF JS Script -->");
                writer.WriteLine("<script type=\"text/javascript\" src=\"" + currentWeb.Site.Url + "/Style%20Library/RemoveFS/js/Hide-Follow-Share.js\"></script>");
            }
        }
    }
}
